package com.toe.user.webapi.controller;


import com.toe.common.restful.JsonPage;
import com.toe.common.restful.JsonResult;
import com.toe.pojo.dto.user.UserAddressDTO;
import com.toe.pojo.dto.user.UserAdminRoleAddDTO;
import com.toe.pojo.vo.user.UserAddressVO;
import com.toe.pojo.vo.user.UserAdminRoleVO;
import com.toe.user.service.UserAddressService;
import com.toe.user.service.UserAdminRoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 陶涛
 * @since 2022-07-19
 */
@RestController
@RequestMapping("/webapi/user-admin-role")
@Api(tags = "管理员角色映射模块")
public class UserAdminRoleController {
    @Autowired
    private UserAdminRoleService userAdminRoleService;

    @ApiOperation("新增映射")
    @PostMapping("/insert")
    public JsonResult<Void> insert(@RequestBody UserAdminRoleAddDTO userAdminRoleAddDTO){
        userAdminRoleService.insert(userAdminRoleAddDTO);
        return JsonResult.ok();
    }

    @ApiOperation("删除映射")
    @PostMapping("/delete")
    public JsonResult<Void> delete(long id){
        userAdminRoleService.delete(id);
        return JsonResult.ok();
    }

    @ApiOperation("删除指定映射")
    @PostMapping("/delete/one")
    public JsonResult<Void> deleteOne(long adminId, long roleId) {
        userAdminRoleService.deleteOne(adminId, roleId);
        return JsonResult.ok();
    }

    @ApiOperation("查询全部映射")
    @PostMapping("/select")
    public JsonResult<List<UserAdminRoleVO>> selectAllAdminRole() {
        List<UserAdminRoleVO> userAdminRoleVOS = userAdminRoleService.selectAllAdminRole();
        return JsonResult.ok(userAdminRoleVOS);
    }

    @ApiOperation("查询某个映射")
    @PostMapping("/select/ne")
    public JsonResult<Boolean> selectOneAdminRole(long adminId, long roleId) {
        Boolean aBoolean = userAdminRoleService.selectOneAdminRole(adminId, roleId);
        return JsonResult.ok(aBoolean);
    }
}

